/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.socialNet.dao.implementations;

import com.bionic.socialNet.dao.abstractClasses.DAOFactory;
import com.bionic.socialNet.dao.interfaces.IMessageDAO;
import com.bionic.socialNet.dao.interfaces.IProfileDAO;
import com.bionic.socialNet.dao.interfaces.IUserConnectionsDAO;
import com.bionic.socialNet.dao.interfaces.IUserDAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Ann
 */
public class OraDAOFactory extends DAOFactory {
Connection connection;
    // метод для создания соединений к Oracle
   

    @Override
    public IUserDAO getUserDAO() {
        return new OraUser();
    }

    @Override
    public IProfileDAO getProfileDAO() {
       return new OraProfile();
    }

    @Override
    public IUserConnectionsDAO getUserConnectionsDAO() {
        return new OraUserConnections();
    }

    @Override
    public IMessageDAO getMessageDAO() {
        return new OraMessage();
    }

    // To delete
    
    @Deprecated
    public Connection getConnection() {
     return connection;
    }
    
     @Deprecated
    public void CreateConnection(String LoginDB, String PasswdDB, String DBURL) {

        final String DefaultURL = "jdbc:oracle:thin:@localhost:1521:xe";
        String URL = "";
        if (DBURL == null) {
            URL = DefaultURL;
        } else {
            URL = DBURL;
        }        
        //System.setProperty("user.language", "ru_RU");
        System.setProperty("user.language", "en_US");
        try {
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            connection = DriverManager.getConnection(URL, LoginDB, PasswdDB);

        } catch (Exception e) {
            // REDO it: need to return client errror
            if (e instanceof SQLException) {
                if (((SQLException) e).getErrorCode() == 1017) {
                    //Message.ShowMessage(Constants.CNST_LOGIN_PASSWORD_ERROR,							MsgType.Error);
                } else {
                	System.out.println("Error " + e.getMessage());
                    //Message.ShowMessage(Constants.CNST_CONNECTION_ERROR + e.getMessage(),MsgType.Error);
                    System.exit(0);
                }
            }
        }
    }
}
